//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    fulldata:app.data,
  },

  //事件处理函数
  onShow: function () {
    console.log(app.globalData.hasUserInfo)
    wx.getSetting({
      success: function (res) {
        if (app.globalData.hasUserInfo) {
          wx.showModal({
            content: '您是优秀的授权用户',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户已知晓后果')
                console.log('用户已经前往主页')
                wx.navigateTo({
                  url: '../index2/index2'
                })
              }
            }
          });
        }
        else {
          openAlert: {
            wx.showModal({
              content: '您还没有授权',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '../login/login2'
                  })
                  console.log('用户已知晓后果')
                }
              }
            });
          }
        }
      }
    })
  },
  onLoad: function () {
    // 查看是否授权
    console.log(app.globalData.hasUserInfo)
    wx.getSetting({
      success: function (res) {
        if (app.globalData.hasUserInfo) {
          wx.showModal({
            content: '您是优秀的授权用户',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户已知晓后果')
              }
            }
          });
        }
        else{
          openAlert: {
            wx.showModal({
              content: '您还没有授权',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '../login/login2'
                  })
                  console.log('用户已知晓后果')
                }
              }
            });
          }
        }
      }
    })
  }
})
